

import dt = module("main/org/sdmx/model/v2/base/type/DataType");
import rep = module("main/org/sdmx/model/v2/base/structure/Representation");
	
/**
	* A length range, defined by a minimum and maximum lengths.
	* 
	* @author Xavier Sosnovsky, Anthony Morel
	* 
	* @see org.sdmx.model.v2.base.type.DataType
	*/ 
export class LengthRange implements rep.Representation {
		
	/*==============================Fields================================*/
		
	private _minLength:number;
		
	private _maxLength:number;
		
	private _dataType:string;
		
	/*===========================Constructor==============================*/
		
	/**
		* Constructs an object defining the data type and the minimum and 
		* maximum allowed length of a representation.
		* 
		* @param minLength The minimum length allowed
		* @param maxLength The maximum length allowed
		* @param type The type of data
		*/
	constructor(minLength:number = NaN, 
        maxLength: number = NaN, type:string = null) {

		this._minLength = minLength;
        this._maxLength = maxLength;
        this.setDataType(type);
	}
		
	/*============================Accessors===============================*/
		
	/**
		* @private 
		*/
	public setMinLength(minLength:number) {
        this._minLength = minLength;
	}
		
	/**
		* The minimum length allowed
		*/
	public getMinLength():number {
        return this._minLength;
	}
		
	/**
		* @private 
		*/
	public setMaxLength(maxLength:number) {
        this._maxLength = maxLength;
	}
		
	/**
		* The maximum length allowed
		*/
	public getMaxLength():number {
        return this._maxLength;
	}
		
	/**
		* @private 
		*/
	public setDataType(dataType:string) {
		if (dataType != null && !dt.DataType.contains(dataType)) {
			throw new Error(dataType + " is not a valid SDMX" + 
					" data type.");
		} else {
            this._dataType = dataType;
		}
	}
		
	/**
		* The type of data as defined in org.sdmx.model.v2.base.type.DataType.
		* 
		* @throws ArgumentError <code>ArgumentError</code>: If the supplied 
		* data type is not a valid SDMX data type.
		*/
	public getDataType():string {
        return this._dataType;
	}
}